package cn.itcast.hotel.mq;

import cn.itcast.hotel.constants.MqConstants;
import cn.itcast.hotel.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author zhangchengzheng
 * @date 2024/6/24 16:44
 * @change 2024/6/24 16:44 by zhangchengzheng for init
 */

@Component
@Slf4j
public class HotelListener {


    @Resource
    private IHotelService hotelService;


    /**
     * 监听酒店新增或者修改的业务
     * @param id  酒店id
     */
    @RabbitListener(queues = MqConstants.HOTEL_INSERT_QUEUE)
    public void listenInsertOrUpdate(Long id) {
        log.info("监听到新增或更新酒店消息:{}", id);
        hotelService.insetById(id);
    }


    /**
     * 监听酒店删除的业务
     * @param id 酒店id
     */
    @RabbitListener(queues = MqConstants.HOTEL_DELETE_QUEUE)
    public void listenDelete(Long id) {
        log.info("监听到删除酒店消息:{}", id);
        hotelService.deleteById(id);
    }

}
